import { ElMessage } from 'element-plus';
import { createRouter, createWebHashHistory } from 'vue-router';
import routes from './routes';

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

const isDevelopment =
    import.meta.env.DEV || import.meta.env.MODE === 'dev' || import.meta.env.MODE.includes('prod_test');


router.beforeEach(async (to, from, next) => {
    if (['/login', '/unauthorized', '/approveThirdPush'].includes(to.path)) {
        next();
    } else {
      //先获取是否有token
      const token = sessionStorage.getItem('token');
      if(token){
        next();
      }else{
        next('/login');
      }
      
    }
});

export default router;
